package com.lihui.连续最大和;

import java.util.Scanner;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/11/24  21:02
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = sc.nextInt();
            }
            //定义两个变量，来接收最大值
            int sum = arr[0];
            int res = arr[0];
            //遍历数组的每个元素 进行操作
            for (int i = 1; i < arr.length; i++) {
                if(sum + arr[i] > arr[i]){
                    sum += arr[i];
                }else{
                    sum = arr[i];
                }
                if(sum > res){
                    res = sum;
                }
            }
            System.out.println(res);
        }
    }
}
